var windowW = $(window).width();
$(function () {
  
    var element = ""
   
    var playvideo = ""
    ellipsis()
    var pcInit = $(window).width() > 991 ? true : false
    var moInit = $(window).width() <= 991 ? true : false

    var atlas_pc = new Swiper('.js_atlas_pc', {
        preventLinksPropagation: true,
        touchMoveStopPropagation: true,
        resizeReInit: true,
        onSlideClick: function (swiper) {
            bigPic();
        },
        roundLengths: true,
        onSlideChangeEnd: function (swiper) {
            var index = swiper.activeIndex;
            if (index == 0) {
                $(".pclunbio .prev").addClass("noswiper")
            } else {
                $(".pclunbio .prev").removeClass("noswiper")
            }
            if (index == $(".js_atlas_pc .swiper-slide").length - 1) {
                $(".pclunbio .next").addClass("noswiper")
            } else {
                $(".pclunbio .next").removeClass("noswiper")
            }

        },
        resizeReInit: true,
        onFirstInit: function (swiper) {
            $(".pclunbio").addClass("o_df-show-block o_df-show-block o_md-hide o_sm-hide o_xs-hide")

        },
        onInit: function () {
      
        }
    })
    $(".js_pclunbio_prev").click(function () {
        atlas_pc.swipePrev();
    })
    $(".js_pclunbio_next").click(function () {
        atlas_pc.swipeNext();

    })
    var atlas_mo = new Swiper('.js_atlas_mo', {
        initialSlide: 0,
        pagination: '.molunbio .pagination',
        paginationClickable: true,
        resizeReInit: true,
        roundLengths: true,
        onSlideClick: function (swiper) {
            bigPic()
        },
        onFirstInit: function (swiper) {
            $(".molunbio").addClass(" o_df-hide o_lg-hide o_md-show-block o_sm-show-block o_xs-show-block")

        },
        onInit: function () {
      
        }
    })

    $(".pclunbio .js_imglunbo").each(function (index) {
        var $this = $(this)
        var title = $this.attr('data-title')
        var src = $this.find('.o_fixCover').attr('src')
        if ($this.find('.videoMask').length == 0) {

            $(".js_append").append(' <div class="swiper-slide" data-title="' + title + '"><span class="middel">1</span><img class="img" src="' + src + '"></div>')
        }

    })
    // 查看大图
    var viewLargerImage = new Swiper('.js_viewLargerImage .swiper-container', {
        onSlideChangeEnd: function (swiper) {

            var index = swiper.activeIndex;
            $(".js_viewLargerImage_title").text($(".js_append .swiper-slide").eq(index).attr('data-title'))


            if (index == 0) {
                $(".viewLargerImage_prev").addClass("noswiper")
            } else {
                $(".viewLargerImage_prev").removeClass("noswiper")
            }

            if (index == swiper.slides.length - 1) {

                $(".viewLargerImage_next").addClass("noswiper")
            } else {
                $(".viewLargerImage_next").removeClass("noswiper")
            }
        },
        roundLengths: true,
        preventClicksPropagation: true,
    })

    $(".js_viewLargerImage_title").text($(".js_append .swiper-slide").eq(0).attr('data-title'))
    $(".js_viewLargerImage .iconarrow-jiantou-left1").click(function () {
        viewLargerImage.swipePrev();
    })
    $(".js_viewLargerImage .iconarrow-jiantou-right1").click(function () {
        viewLargerImage.swipeNext();
    })
    $(".js_viewLargerImage_close").click(function () {
        $(".js_viewLargerImage").hide()
        $("body").css('overflow', 'auto')
    })
    $(".js_imglunbo").click(function () {
        element = $(this)

    })
    $(".js_viewLargerVideo_close").click(function () {
        $(".js_viewLargerVideo").hide()
        $("body").css('overflow', 'auto')
        try {
            playvideo.dispose()
        } catch (error) {

        }
    })
    // 查看大图



    $(window).resize(function () {
        ellipsis()
        if ($(window).width() > 991) {
            if (!!pcInit) {
                atlas_pc.reInit();
                pcInit = true
            }
        } else {
            if (!!moInit) {
                atlas_mo.reInit();
                moInit = true
            }
        }
      
        ckdt()
    });


    $(".o_picture").each(function () {
        $(this).oPicture({
            //自定义节点宽度
            //sm:544,md:700,lg:992,xl:1200,
        }).init();
    });

    function ellipsis() {
        var web_address = $(".web_address").width()
        var web_address_group = $(".web_address_group").width()
        $(".js_ellipsis").width(web_address - web_address_group)
    }





    function ckdt() {
        var height = $(window).height()
        $('.js_viewLargerImage .swiper-container').css({
            "height": height + "px",
            "lineHeight": height + "px"
        })
        if (windowW <= 1199) {
            $(".js_viewLargerImage img").css({
                "max-height": height - $(".js_viewLargerImage_title").height() - $(".js_viewLargerImage_close").height() - 28 + "px",
            })
        } else {
            $(".js_viewLargerImage img").css({
                "max-height": '100%'
            })
        }
        $(".js_viewLargerVideo .js_videoBox").css({
            "max-height": height - $(".js_viewLargerVideo_title").height() - $(".js_viewLargerVideo_close").height() - 28 + "px",
        })
    }

    function bigPic() {
        try {
            setTimeout(function () {
                var $this = element;
                if ($this.find(".videoMask").length == 0) {
                    var nowImgSrc = $this.find("img").attr("src")
                    var imglist = $(".js_append .img")
                    var index = 0;
                    for (var i = 0; i < imglist.length; i++) {
                        if (nowImgSrc == imglist.eq(i).attr("src")) {
                            index = i
                            break;
                        }
                    }
                    $(".js_viewLargerImage_title").text($(".js_append .swiper-slide").eq(index).attr('data-title'))
                    $(".js_viewLargerImage").show()
                    ckdt()
                    viewLargerImage.reInit();
                    viewLargerImage.swipeTo(index, 1, true);
                    if (index == 0) {
                        $(".viewLargerImage_prev").addClass("noswiper")
                    }
                    if (
                        index == imglist.length
                    ) {
                        $(".viewLargerImage_next").addClass("noswiper")
                    }


                } else {
                    var DURL = $this.attr("data-video")
                    var PIC = $this.attr("data-poster")
                    var html = ''
                    html += ' <video id="pvideo" controls="controls" class="video-js vjs-default-skin vjs-big-play-centered" x5-video-player-type="h5" x5-video-player-fullscreen="false"  playsinline="true" webkit-playsinline="true" preload="none" name="media" poster="' + PIC + '" >'
                    html += ' <source src="' + DURL + '" type="video/mp4" />'
                    html += '</video>'
                    $(".js_videoBox").html(html)
                    playvideo = videojs("pvideo", {
                        techOrder: ["html5", "flash"]
                    });

                    $(".js_viewLargerVideo_title").text($this.attr("data-title"))
                    $(".js_viewLargerVideo").show()
                    ckdt()
                }
                $("body").css('overflow', 'hidden')
            }, 100)
        } catch (error) {

        }

    }

})
// $('.swiper-slide img,.swiper-slide').mousedown(function (event) {

//     if (event.which == 3) {
//         event.stopPropagation();
//     }
// })